<script>
	import {
		defineComponent,
		onMounted
	} from 'vue';
	import {
		useStore
	} from "vuex"
	export default defineComponent({
		components: {},

		setup() {
			const store = useStore()
			// 在页面刷新时将store保存到sessionStorage里
			window.addEventListener('beforeunload', () => {
				sessionStorage.setItem('store', JSON.stringify(store.state))
			})
			onMounted(() => {
				// 在页面加载时读取sessionStorage
				if (sessionStorage.getItem('store')) {
					store.replaceState(Object.assign({}, store.state, JSON.parse(sessionStorage.getItem(
						'store'))))
				}
			})
			return {};
		},

	});
</script>

<template>
	<router-view></router-view>
</template>

<style lang="scss">
</style>
